package com.bms.hystrix.controller.gllw;

import com.bms.hystrix.pojo.LunWen;
import com.bms.hystrix.service.gllw.CheckService;
import io.swagger.annotations.*;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.Map;

// 基于feign中创建的controller进行改造，这次注入的是service
@RestController
@RequestMapping("guanLiLunWen")
@Api(value = "论文管理与检索表(LunWen)管理",tags = "论文管理与检索表(LunWen)管理接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
public class CheckController {
    @Resource
    private CheckService checkService;

    /*
    这里类似于ribbon，提供一个对外访问的接口地址，
    然后根据serviceFeignByCheck接口来决定调用哪一个子模块服务和哪一个接口地址
     */
//    @RequestMapping(value = "/check",method = RequestMethod.GET,
//            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public Map check(String name) {
//        return checkService.check(name);
//    }



    /**
     * 联合模糊查询论文数据
     * @param  tiMu,zuoZhe,faBiaoWeiZhi,lunWenLeiBie,faBiaoShiJianQiShi,faBiaoShiJianJieShu 联合模糊查询的内容
     * @return 数据
     */
    @RequestMapping(value = "lianHeChaXun", method = RequestMethod.GET)
    @ApiOperation(value = "联合，模糊查询已发表论文数据列表接口",notes = "返回所有已发表论文的数据列表",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tiMu",value = "请输论文题目",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "zuoZhe",value = "请输入论文作者",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "faBiaoWeiZhi",value = "请输入论文发表位置",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "lunWenLeiBie",value = "请输入论文类别",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "faBiaoShiJianQiShi",value = "请输入论文发表的起始时间",paramType = "query",dataType = "Date",required = false),
            @ApiImplicitParam(name = "faBiaoShiJianJieShu",value = "请输入论文发表的结束时间",paramType = "query",dataType = "Date",required = false)
    })
    public Map<String, Object> lianHeChaXun(String tiMu, String zuoZhe, String faBiaoWeiZhi,
                                            String lunWenLeiBie, Date faBiaoShiJianQiShi, Date faBiaoShiJianJieShu) {
        return checkService.lianHeChaXun(tiMu, zuoZhe,faBiaoWeiZhi,lunWenLeiBie,faBiaoShiJianQiShi,faBiaoShiJianJieShu);
    }



    /**
     * 通过id查询论文的物理地址数据
     * @param  id id
     * @return 数据
     */
    @RequestMapping(value = "chaXunById", method = RequestMethod.GET)
    @ApiOperation(value = "通过id查询论文的物理地址数据接口",notes = "返回此条已发表论文的地址数据",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "请输论文id",paramType = "query",dataType = "Integer",required = false)
    })
    public Map<String, Object> chaXunById(int id) {
        return checkService.chaXunById(id);
    }



    /**
     * 查询所有已发表的论文数据接口
     * @return 返回所有数据
     */
    @RequestMapping(value = "chaXunAll", method = RequestMethod.GET)
    @ApiOperation(value = "查询所有已发表的论文数据接口",notes = "查询所有已发表的论文数据接口",httpMethod = "GET")
    public Map<String, Object> chaXunAll() {
        return checkService.chaXunAll();
    }



    /**
     * 通过论文状态查询论文数据，含分页
     * @param  page page
     * @return 数据
     */
    @RequestMapping(value = "chaXunCaoGao", method = RequestMethod.GET)
    @ApiOperation(value = "查询未发表的论文数据，含分页的数据接口",notes = "返回未发表的论文的地址数据",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "请输入page",paramType = "query",dataType = "Integer",required = false)
    })
    public Map<String, Object> chaXunCaoGao(int page) {
        return checkService.chaXunCaoGao(page);
    }


    /**
     * 通过论文类别查询论文数据，含分页
     * @param  lunWenLeiBie
     * @return 数据
     */
    @RequestMapping(value = "chaXunByLeiBie", method = RequestMethod.GET)
    @ApiOperation(value = "通过id查询论文的物理地址数据接口",notes = "返回此条已发表论文的地址数据",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lunWenLeiBie",value = "请输入论文类别",paramType = "query",dataType = "String",required = false)
    })
    public Map<String, Object> chaXunByLeiBie(String lunWenLeiBie) {
        return checkService.chaXunByLeiBie(lunWenLeiBie);
    }




    /**
     * 查询分页
     * @param  page
     * @return 数据
     */
    @RequestMapping(value = "chaXunFenYe", method = RequestMethod.GET)
    @ApiOperation(value = "查询论文分页数据接口",notes = "返回分页数据",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "请输入page",paramType = "query",dataType = "Integer",required = false)
    })
    public Map<String, Object> chaXunFenYe(int page) {
        return checkService.chaXunFenYe(page);
    }




    /**
     * 查询分页
     * @param  page
     * @return 数据
     */
    @RequestMapping(value = "chaXunFenYe01", method = RequestMethod.GET)
    @ApiOperation(value = "查询论文分页数据接口",notes = "返回分页数据",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "请输入page",paramType = "query",dataType = "Integer",required = false)
//            @ApiImplicitParam(name = "tiMu",value = "请输入论文类别",paramType = "query",dataType = "Integer",required = false),
//            @ApiImplicitParam(name = "zuoZhe",value = "请输入论文类别",paramType = "query",dataType = "Integer",required = false),
//            @ApiImplicitParam(name = "faBiaoWeiZhi",value = "请输入论文类别",paramType = "query",dataType = "Integer",required = false),
//            @ApiImplicitParam(name = "lunWenLeiBie",value = "请输入论文类别",paramType = "query",dataType = "Integer",required = false),
//            @ApiImplicitParam(name = "faBiaoShiJianQiShi",value = "请输入论文类别",paramType = "query",dataType = "Integer",required = false),
//            @ApiImplicitParam(name = "faBiaoShiJianJieShu",value = "请输入论文类别",paramType = "query",dataType = "Integer",required = false)
    })
    public Map<String, Object> chaXunFenYe01(int page, String tiMu, String zuoZhe,
                                             String faBiaoWeiZhi, String lunWenLeiBie,
                                             String faBiaoShiJianQiShi, String faBiaoShiJianJieShu) {
        return checkService.chaXunFenYe01(page,tiMu, zuoZhe, faBiaoWeiZhi, lunWenLeiBie,
                faBiaoShiJianQiShi, faBiaoShiJianJieShu);
    }




    /**
     * 通过ID更新论文表的数据
     *
     * @param lunWen,request,file 数据库对应的pojo数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "gengXinById", method = RequestMethod.POST)
    @ApiOperation(value = "通过主键更新一个**的接口",notes = "通过主键更新一个**的接口",httpMethod = "POST")
    public Map<String, Object> gengXinById(
//                                            @RequestBody @ApiParam(name = "lunWen",value = "pojo模型",required = false),
//                                           @RequestBody @ApiParam(name = "request",value = "pojo模型",required = false),
//                                           @RequestBody @ApiParam(name = "file",value = "pojo模型",required = false)
                                                   LunWen lunWen,HttpServletRequest request,MultipartFile file) {
        return checkService.gengXinById(lunWen,request,file);
    }



    /**
     * 通过论文地址下载附件数据
     *
     * @param request,response,diZhi 数据库对应的pojo数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "xiaZai", method = RequestMethod.POST)
    @ApiOperation(value = "通过论文地址下载附件数据的接口",notes = "通过论文地址下载附件数据",httpMethod = "POST")
    public Map<String, Object> xiaZai(
//                                            @RequestBody @ApiParam(name = "request",value = "pojo模型",required = false),
//                                           @RequestBody @ApiParam(name = "response",value = "pojo模型",required = false),
//                                           @RequestBody @ApiParam(name = "diZhi",value = "pojo模型",required = false)
                                                       HttpServletRequest request, HttpServletResponse response, String diZhi) {
        return checkService.xiaZai(request,response,diZhi);
    }



    /**
     * 新增一条论文表数据
     *
     * @param lunWen,request,file 数据库对应的pojo数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "xinZeng", method = RequestMethod.POST)
    @ApiOperation(value = "根据完整记录新增一个**的接口",notes = "根据完整记录新增一个**的接口",httpMethod = "POST")
    public Map<String, Object> xinZeng(
            //不能以json格式上传文件
///            @RequestBody @ApiParam(name = "lunWen",value = "pojo模型",required = false),
//                                           @RequestBody @ApiParam(name = "request",value = "pojo模型",required = false),
//                                           @RequestBody @ApiParam(name = "file",value = "pojo模型",required = false)
                                                   LunWen lunWen,HttpServletRequest request,MultipartFile file) {
        return checkService.xinZeng(lunWen,request,file);
    }


    /**
     * 通过id删除一条论文数据
     *
     * @param id 数据库对应的pojo数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "shanChuById", method = RequestMethod.GET)
    @ApiOperation(value = "通过id删除一条论文数据的接口",notes = "删除一条论文数据数据",httpMethod = "GET")
    public Map<String, Object> shanChuById(
            @RequestBody @ApiParam(name = "id",value = "pojo模型",required = false)
                    String id) {
        return checkService.shanChuById(id);
    }


}
